// pages/huoseListByCityname/huoseListByCityname.js
var app = new getApp();
import Http from '../../utils/http.js';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    city:'KUNMING_ROOM',
    houseList:[],
    loading:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      city:options.city
    })

    this.getRoomList();
    wx.setNavigationBarTitle({
      title: options.city_cn
    })
  },
  getRoomList(){
    wx.showLoading({
      title: '加载中',
      mask: true
    })
    this.setData({
      loading:true
    })
    if (this.data.city === 'TE_JIA_FANG') {
      Http.Request('GET', `/api/customer/commodity/todaySpecialPrice/v1`).then(res => {
        wx.hideLoading();
        this.setData({
          houseList: res,
          loading: false
        })
      }).catch(err => {
        wx.hideLoading();
        app.globalFn.reLoad(this.getRoomList, err)
      })
    }else{
      Http.Request('GET', `/api/customer/commodity/getRoomCommodityByCityRoom/${this.data.city}/v1`).then(res => {
        wx.hideLoading();
        this.setData({
          houseList: res,
          loading: false
        })
      }).catch(err => {
        wx.hideLoading();
        app.globalFn.reLoad(this.getRoomList, err)
      })
    }

  },
  itemClick(e) {
    const commodityCode = e.currentTarget.dataset.item.commodityCode;
    wx.navigateTo({
      url: `../houseList/houseDetail/houseDetail?commodityCode=${commodityCode}`
    })
  },
  onShareAppMessage() {
    app.globalFn.onShareAppMessage()
  }
})